Skip to content

CLB 2nd PR: Add DiffTracker core types, state management, and sync operations#10068

Open
georgeedward2000 wants to merge 2 commits into
kubernetes-sigs:masterfrom
georgeedward2000:enechitoaia/clb-difftracker-engine-2
Open

CLB 2nd PR: Add DiffTracker core types, state management, and sync operations#10068
georgeedward2000 wants to merge 2 commits into
kubernetes-sigs:masterfrom
georgeedward2000:enechitoaia/clb-difftracker-engine-2

Conversation

@georgeedward2000
Copy link
Copy Markdown
Contributor

@georgeedward2000 georgeedward2000 commented Mar 19, 2026

What type of PR is this?

/kind feature

What this PR does / why we need it:

This PR introduces the DiffTracker core package — the foundational types, state management, and diff computation logic for the Container Load Balancer (CLB) feature.

The DiffTracker maintains two parallel state representations:

  • K8s State: Services, Egresses, and Nodes (with Pods and their inbound/outbound identities)
  • NRP State: LoadBalancers, NATGateways, and Locations (with Addresses and service references)

It provides operations to mutate both states and compute the diff between them, determining what needs to be synced to Azure.

Package contents (pkg/provider/difftracker/):

File Content
types.go Core enums (Operation, UpdateAction, SyncStatus), K8s/NRP state model types, DiffTracker struct, input types, sync result types
config.go Config struct with Azure subscription, resource group, location, and ServiceGateway fields
difftracker.go InitializeDiffTracker() constructor with validation
k8s_state_updates.go K8s state mutations: services, egresses, endpoints, pods
nrp_state_updates.go NRP state mutations: LoadBalancers, NATGateways, location/address updates
sync_operations.go Diff computation between K8s and NRP states (GetSyncOperations, GetSyncLoadBalancerServices, GetSyncNRPNATGateways, GetSyncLocationsAddresses)
util.go Enum serialization, DeepEqual, Equals comparison methods

Dependency changes (pkg/util/sets/string.go):

  • Added Equals() method to IgnoreCaseSet for set comparison
  • Added MarshalJSON() method to IgnoreCaseSet for JSON serialization

Test coverage:

  • difftracker_test.go — 14 test functions covering initialization, state updates, sync operations, and end-to-end scenarios
  • util_test.go — 11 test functions covering enum serialization, JSON round-trips, HasPods/HasIdentities helpers, DeepEqual, Equals, and Config.Validate()
  • string_test.go — Added TestEquals (8 sub-tests) for the new IgnoreCaseSet.Equals() method

This is PR 2 in the CLB series, building on the configuration and constants from PR 1 (#9775). Engine-layer code (async processing, updaters, finalizers, metrics, Azure operations) and ServiceGateway API DTOs/mappers are intentionally excluded and will follow in subsequent PRs.

Which issue(s) this PR fixes:

Part of CLB (Container Load Balancer) feature implementation.

Special notes for your reviewer:

  • The isServiceReady() function currently checks NRP state only. In the engine PR (PR 3), it will be extended to also check pendingServiceOps for StateCreated status.
  • A DEFERRED_CODE_TRACKER.md is maintained in the source repo tracking what was excluded and which future PR will add it back.
  • Depends on PR First CLB batch of changes #9775 (First CLB batch — config, constants).

Does this PR introduce a user-facing change?

NONE

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 19, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Hi @georgeedward2000. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@github-actions github-actions Bot added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Mar 19, 2026
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Mar 19, 2026
@k8s-ci-robot k8s-ci-robot requested review from mainred and nilo19 March 19, 2026 13:17
@georgeedward2000 georgeedward2000 changed the title Enechitoaia/clb difftracker engine 2 CLB 2nd PR: Add DiffTracker core types, state management, and sync operations Mar 19, 2026
@georgeedward2000 georgeedward2000 force-pushed the enechitoaia/clb-difftracker-engine-2 branch from e829a97 to 21eafd4 Compare May 18, 2026 07:20
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: georgeedward2000
Once this PR has been reviewed and has the lgtm label, please assign anndono for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Comment thread pkg/provider/difftracker/config.go
Comment thread pkg/provider/difftracker/difftracker.go
Comment thread pkg/provider/difftracker/difftracker.go Outdated
Comment thread pkg/provider/difftracker/types.go Outdated
ResourceTypeEgress = "Egress"
)

func updateK8Resource(input UpdateK8sResource, set *utilsets.IgnoreCaseSet, resourceType string) error {
Copy link
Copy Markdown
Contributor

@nilo19 nilo19 May 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we make it updateK8sResources, or updateKubernetesResources, or enqueueOperation?

Comment thread pkg/provider/difftracker/k8s_state_updates.go Outdated
Introduces the difftracker package with core K8s/NRP state tracking,
diff computation, and state mutation logic.
Includes comprehensive test coverage (25+ test functions).
// enqueueK8sResourceOperation applies the requested operation (ADD/REMOVE) to the
// in-memory K8s resource set. It does not perform any Azure update calls; it only
// mutates the local desired-state model that will later be reconciled with NRP.
func enqueueK8sResourceOperation(input UpdateK8sResource, set *utilsets.IgnoreCaseSet, resourceType string) error {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason why this is not a private method of diffTracker? All other funcs here are under diffTracker.

// DiffTracker keeps track of the state of the K8s cluster and NRP
// --------------------------------------------------------------------------------
type NRPAddress struct {
Services *utilsets.IgnoreCaseSet // all inbound and outbound identities
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it store kubernetes service names?

}

type NRPLocation struct {
Addresses map[string]NRPAddress
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please elaborate what address mean in the context of containerLB?

type NRPState struct {
LoadBalancers *utilsets.IgnoreCaseSet
NATGateways *utilsets.IgnoreCaseSet
Locations map[string]NRPLocation
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is Location geological region, like eastus2?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. kind/feature Categorizes issue or PR as related to a new feature. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants